﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.UI;
using System.Web.UI.WebControls;
using Ecopsy.Tools;
using FormControllers;
using AgencyEntityLib.BaseEntity;
using Ecopsy.DataTier;
using System.Threading;
using System.Collections;
using Grishko.UI;

public partial class iFrameAdmin_ConstractionEditor : iAdmin_Page 
{
    Func<ListViewDataItem, bool> LvUpdCmd=null;    
    

    protected void Page_Load(object sender, EventArgs e)
    {     
        if (!IsPostBack)        
                MyDataBind();
        
        MyInit();
    }

    
    /// <summary>
    /// Прорисовка карты
    /// </summary>
    private void RefreshMap()
    {
        ScriptManager.RegisterStartupScript(this, GetType(), Guid .NewGuid ().ToString (), "EditPointScript();", true);
    }
    private void TogglePanels()
    {
         
        
        
     
    }

    protected override void OnDataBinding(EventArgs e)
    {
        base.OnDataBinding(e);
    }

    protected void MyInit()
    {
        //привязать событие открыть закрыть lvSideeditor
        if (lvSideList.EditItem != null)
        {
            Ctl_SideEditor r = (Ctl_SideEditor)lvSideList.EditItem.FindControl("crlSideEditor1");
            r.OnButtonClick = OnSideEditorClick;
            r.OnMyDataChanged = OnSideDataChanged;

        }
        
        if (lvAdresProgramm.EditItem != null)
        {
            TreeDictionaryControl_Rb r1 = (TreeDictionaryControl_Rb)lvAdresProgramm.EditItem.FindControl("tv_AdresProgramm");
            r1.F_DataSource = iPageController.TreeDictionaryContext.GetAdressProgramm;
        }

        
        SetAlertForTextBox(this.Controls, "TextBox", "onChange", "ShowAlert()");
        SetMsg_EditStatus();
                
        
    }
    protected  bool  OnSideEditorClick()
    {
        lvSideList.EditIndex = -1;
        lvSideList.DataSource = Constraction.SideList.ToList<Side>(); 
        lvSideList.DataBind();
        return true;
    }
    protected void SetMsg_EditStatus()
    {
        lblClientStatus.DataBind();
        updStatus.Update();
    }

    private void MyDataBind()
    {
        lvConstractionGID.DataSource = grdConstractionAsCollection;
        lvConstractionType.DataSource = grdConstractionAsCollection;
        lvAdresProgramm.DataSource = grdConstractionAsCollection;
        lvCommonCondition.DataSource = grdConstractionAsCollection;
        lvGeoBinding.DataSource = grdConstractionAsCollection;
        lvMapEditor.DataSource = grdConstractionAsCollection;
        lvTransportLocation.DataSource = grdConstractionAsCollection;
        lvSideList.DataSource = Constraction.SideList.ToList <Side>() ;
        
        DataBind();
    }

    protected string GetStateVisible()
    {
      
        if (!(Constraction.State==EntityState .Loaded) ) 
            return string.Empty;        

        foreach (Entity item in Constraction.SideList)
        {
            if (item.State != EntityState.Loaded) return string.Empty;
        }
        return GlobalConstants .cssHidden ;

    }

    #region DataSource

    protected  F_TreeDataSource GetAdresSource()
    {
        return GetAdresSource("chTree", "chTree", "ctl00_cphBody_hfSelAdrId");
    }

   

    protected  F_TreeDataSource GetLocationDescribe()
    {
        return GetLocationDescribe("chTree", "chTree", "ctl00_cphBody_hfSelLoacationId");
          
    }

    

    #endregion

    private bool rbIsChecked_ConstractionType(TreeEntitySingle Node)
    {
        return false;
    }
    
    private bool rbIsChecked_AdressProgramm(TreeEntitySingle Node)
    {
        return false;
    }

    protected  void ItemEditing(object sender, ListViewEditEventArgs e)
    {
        ListView lv = (ListView)sender;
        TreeDictionaryControl_Rb tv = null;
        TreeEntitySingle source=null;
        switch (lv.ID)
        {
            case "lvConstractionType":
                source=iAdmin_Page.TreeDictionaryContext.GetConstractionType   ();
                tv = (TreeDictionaryControl_Rb)lvConstractionType.EditItem.FindControl("tv_ConstractionType");                
                tv.TreeDictionaryItemValue =  (Constraction.ConstractionType==null? iFrameAdmin_ConstractionEditor.TreeDictionaryContext.GetConstractionType().BuildValue ():Constraction.ConstractionType) ;  
                tv.DataBind();                
                break;
            case "lvAdresProgramm":
                tv = (TreeDictionaryControl_Rb)lvAdresProgramm.EditItem.FindControl("tv_AdresProgramm");
                tv.F_DataSource = iPageController.TreeDictionaryContext.GetAdressProgramm;
                tv.TreeDictionaryItemValue = Constraction.AdressProgramm ;
                tv.DataBind();
                break;
            case "lvCommonCondition":
                tv = (TreeDictionaryControl_Rb)lvCommonCondition.EditItem.FindControl("tv_Condition");
                tv.TreeDictionaryItemValue = (Constraction.ConstractionCondition == null ? iFrameAdmin_ConstractionEditor.TreeDictionaryContext.GetConstractionCondition().BuildValue() : Constraction.ConstractionCondition);                  
                tv.DataBind();
                break;
            case "lvGeoBinding":
                tv = (TreeDictionaryControl_Rb)lvGeoBinding.EditItem.FindControl("tv_GeoBinding");
                tv.TreeDictionaryItemValue = (Constraction.GeoBinding == null ? iFrameAdmin_ConstractionEditor.TreeDictionaryContext.GetGeoBinding().BuildValue() : Constraction.GeoBinding );                                      
                tv.DataBind();                
                break;
            case "lvMapEditor":
                RefreshMap();
                break;
            case "lvTransportLocation":
                tv = (TreeDictionaryControl_Rb)lvTransportLocation.EditItem.FindControl("tv_Location");
                tv.TreeDictionaryItemValue = (Constraction.LocationDescribe== null ? iFrameAdmin_ConstractionEditor.TreeDictionaryContext.GetTransportLocation().BuildValue() : Constraction.LocationDescribe);
                tv.DataBind();                
                break;  
        }

    }
    protected void MultCheckTree_TreeNodeDataBound(object sender, TreeNodeEventArgs e)
    {
        string s = CmdStringEnv.GetParam(e.Node.DataPath, "Selected");
        e.Node.Checked = s.IndexOf("True") > -1;
    }


    private bool UpdateConstractionGID(ListViewDataItem item)
    {   
       TextBox  t = (TextBox)lvConstractionGID.EditItem.FindControl("txtGID"); 
       Constraction.GID = t.Text ;       
        return true;
    }    

    private bool UpdateConstractionType(ListViewDataItem item)
    {
        TreeDictionaryControl_Rb  tv;        
        tv = (TreeDictionaryControl_Rb)lvConstractionType.EditItem.FindControl("tv_ConstractionType");            
        Constraction.ConstractionType= tv.TreeDictionaryItemValue;        
        return true;
    }    
    
    private bool UpdateAdresProgramm(ListViewDataItem item)
    {
        TreeDictionaryControl_Rb tv;
        tv = (TreeDictionaryControl_Rb)lvAdresProgramm.EditItem.FindControl("tv_AdresProgramm");         
        Constraction.AdressProgramm = tv.TreeDictionaryItemValue;
        return true;
    }    
    
    private bool UpdateCommonCondition(ListViewDataItem item)
    {
        TreeDictionaryControl_Rb tv = (TreeDictionaryControl_Rb)lvCommonCondition.EditItem.FindControl("tv_Condition");
        Constraction.ConstractionCondition = tv.TreeDictionaryItemValue;
        return true;
    }
    
    private bool UpdateAddCondition(ListViewDataItem item)
    {
        TreeDictionaryControl_Rb tv = (TreeDictionaryControl_Rb)lvGeoBinding.EditItem.FindControl("tv_GeoBinding");
        Constraction.GeoBinding = tv.TreeDictionaryItemValue;
        return true;
        
    }

    private bool UpdatelvMapEditor(ListViewDataItem item)
    {
        Constraction.MapX = hfX.Value;
        Constraction.MapY = hfY.Value;
        return true;
    }
   
    private bool UpdateTransportLocation(ListViewDataItem item)
    {
        TreeDictionaryControl_Rb tv = (TreeDictionaryControl_Rb)lvTransportLocation.EditItem.FindControl("tv_Location");
            Constraction.LocationDescribe= tv.TreeDictionaryItemValue;
            return true;

    }


    private void  BuildPropertyVal_(TreeNode nd, TreeDictionaryItemValue Value )
    {
        List<TreeNode> l = nd.ChBoxToList();
        TreeNode[] arr = l.ToArray<TreeNode>();
        Value.ChildNodes.Clear(); 

           //подливаем значния 
        for (int i = 0; i < arr.Length; i++)
        {
            string s = CmdStringEnv.GetParam(arr[i].DataPath, "ID");
            Value .AddValue (s);            
        }

    }
    

    protected  void ItemCommand(object sender, ListViewCommandEventArgs e)
    {
        if (string.Empty == e.CommandName) return;        
        ListView lv = (ListView)sender;
        switch (lv.ID)
        {

            case "lvConstractionGID":
                LvUpdCmd = UpdateConstractionGID;
                break;

            case "lvConstractionType":
                LvUpdCmd = UpdateConstractionType;
                break;
            case "lvAdresProgramm":
                LvUpdCmd = UpdateAdresProgramm;
                break;
            case "lvCommonCondition":
                LvUpdCmd = UpdateCommonCondition;
                break;
            case "lvGeoBinding":                 
                LvUpdCmd = UpdateAddCondition;
                break;
            case "lvTransportLocation":
                LvUpdCmd = UpdateTransportLocation;
                break;
            case "lvMapEditor":
                LvUpdCmd = UpdatelvMapEditor;
                break;
        }
     
        switch (e.CommandName)
        {
            case "Edit":
                {   
                    ListViewDataItem d = (ListViewDataItem)e.Item;
                    lv.EditIndex = d.DataItemIndex;                                                          
                    break;
                }
            case "Insert":
                {
                    break;
                }
            case "Update":
                {
                    if (LvUpdCmd((ListViewDataItem)e.Item)) lv.EditIndex = -1;
                    //SetMsg_EditStatus ();
                    break;
                }
            case "Delete":
                {
                    //DeleteCustomer(e.CommandArgument as string);
                    break;
                }
        }

        switch (lv.ID)
        {

            case "lvSideList":                
                lv.DataSource = Constraction.SideList.ToList <Side>();
                break;
            default:
                    lv.DataSource = grdConstractionAsCollection; ;
                break ;
        }
        lv.DataBind();
        SetAlertForTextBox(this.Controls, "TextBox", "onChange", "ShowAlert()");
        SetMsg_EditStatus();
    }

    
    protected void btnSaveCommonInfo_Click(object sender, EventArgs e)
    {
        ReadForm();        
        List<string> err = new List<string>();
        if (Constraction.BusinesRulesEngine.Check())
        {
            SaveConstraction();
            lblClientStatus.CssClass = GlobalConstants.cssHidden;
        }
    }

   
    protected void ReadForm()
    {
        
        Constraction.bLight = chLight.Checked ;
        Constraction.Streets = txtStreets.Text;
        Constraction.dtCreate = (txt_dtCreate.Text == string.Empty ? GlobalConstants.MinDate : Convert.ToDateTime(txt_dtCreate.Text));
        Constraction.dtDestroy = (txt_dtDestroy.Text == string.Empty ? GlobalConstants.MaxDate : Convert.ToDateTime(txt_dtDestroy.Text));        
        Constraction.Describe = txtDescribe.Text;
   
    }
    protected void SaveConstraction()
    {
        
        wsConstractions ws = (wsConstractions)GlobalConstants.CurrentAgency.WS_FactoryList[WS_FactoryList.wsKey_Constraction];                    
        
        // сохраняем если новая конструкция - то ждем - существующая - асинхронно
        if (IsNewRecord(ConstractionID))
        {
            Constraction c = ws.SaveConstraction(Constraction);
            Response.Redirect("iFrameAdmin_ConstractionEditor.aspx?" + qConstractionID + "=" + c.ID);
        }
        else
            ///ws.SaveConstraction_Asyn(Constraction);
            ws.SaveConstraction(Constraction);
            

    }

            
        


    protected bool OnSideDataChanged()
    {
        SetMsg_EditStatus();
        return true;
    }
    protected void brnReturn_Click(object sender, EventArgs e)
    {
        Response .Redirect ("iFrameAdmin_Constractions.aspx");
    }
    protected void btnAddSide_Click(object sender, EventArgs e)
    {
        Side side = new Side() { SurfaceCount = 1 };        
        Constraction.SideList.Add(side);  
        MyDataBind();
        
    }




    ////////////////////////////////////////////////////////////////////////

    
    wsConstractions _ws_Constractions = (wsConstractions)GlobalConstants.CurrentAgency.WS_FactoryList[WS_FactoryList.wsKey_Constraction];                    

    protected  string ConstractionID
    {
        get { return Request.QueryString[qConstractionID]; }
    }

    protected  string ConstractionTypeID
    {
        get { return (Request.QueryString[qConstractionTypeID]); }
    }



    
    // сформировать источник данных дерева 
    protected virtual F_TreeDataSource GetTreeSource(String TreeDictionaryType)
    {
        switch (TreeDictionaryType)
        {
            case GlobalConstants.TreeDictionary_AdressProgram:
            return GetAdresSource();

            case GlobalConstants.TreeDictionary_ConstractionType:
            return GetConstractionType();
           
            case GlobalConstants.TreeDictionary_LocationDescribe :
            return GetLocationDescribe ();
        }

        if (GlobalConstants.TreeDictionary_AdressProgram == TreeDictionaryType)
        {
            return GetAdresSource();
        }
        if (GlobalConstants.TreeDictionary_ConstractionType  == TreeDictionaryType)
        {
            return GetConstractionType ();
        }

        /// Для остальных справочников

        Func<TreeEntitySingle, string> f_string = delegate(TreeEntitySingle nd)
        {
            if(null ==nd) return string.Empty ;
            return "<a ID=rbLnk_" + nd.ID + "\"> " + ((TreeDictionaryItem)nd).Name + "</a>";

        };

        TreeDictionaryItemValue TreeVal = null; ;
        switch (TreeDictionaryType)
        {
            case(GlobalConstants.TreeDictionary_ConstractionConditions) :
            TreeVal= Constraction.ConstractionCondition ;
            break ;

            case (GlobalConstants.TreeDictionary_GeoBinding):
            TreeVal = Constraction.GeoBinding;
            break;

        }
        Func<TreeEntitySingle, string> f_path = delegate(TreeEntitySingle nd)
        {
            if (null == nd) return string.Empty;
            bool r = false;
            if (null !=TreeVal) r = TreeVal.ValueExists(nd.ID);
            if (r)
            {
                return "ID=" + nd.ID + ",Selected=True";
            }
            else
            {
                return "ID=" + nd.ID + ",Selected=False";
            }
          
        };


        // определить делегат поставляющий класс определяющий формат ноды в дереве
        Func<TreeEntitySingle, F_TreeDataSource.F_TreeDataSourceView.F_TreeHierarchyData> f = delegate(TreeEntitySingle _tr)
        {
            return (TreeNodeFormatter_Fn)new TreeNodeFormatter_Fn(_tr, f_path, f_string);
        };

        TreeDictionaryItem TreeSource = null;
        
        switch (TreeDictionaryType)
        {
            case GlobalConstants.TreeDictionary_ConstractionConditions:                
                return new F_TreeDataSource(iPageController.TreeDictionaryContext.GetConstractionCondition(), f);
                break ;

            case GlobalConstants.TreeDictionary_GeoBinding:
                return new F_TreeDataSource(iPageController.TreeDictionaryContext.GetGeoBinding(), f);
                break;
            
            case GlobalConstants.TreeDictionary_ConstractionType :
                return new F_TreeDataSource(iPageController.TreeDictionaryContext.GetConstractionType(), f);
                break;
            
            case GlobalConstants.TreeDictionary_LocationDescribe:
                return new F_TreeDataSource(iPageController.TreeDictionaryContext.GetTransportLocation(), f);            
            
            case GlobalConstants.TreeDictionary_TaskCategory :
                return new F_TreeDataSource(iPageController.TreeDictionaryContext.GetTaskCategory (), f);
                break;
        }

        return null;
        
    }
  
   

    protected virtual F_TreeDataSource GetAdresSource(string _DivClass,string _NodeClass , string _HfId)
    {
    
        // Инициализировать RbCheckBox 
        TreeNodeFormatter_Rb.TreeRbContext f = new TreeNodeFormatter_Rb.TreeRbContext()
        {
                DivClass =_DivClass, 
                NodeClass=_NodeClass , 
                HfId=_HfId ,           
            
            // опредеить функцию решающую нажат чек бокс или нет 
            OnChBind = delegate(TreeEntitySingle _tr)
            {
                if (null == Constraction.AdressProgramm) return false;
                if (_tr.ChildNodes.Count > 0) return false;
                return Constraction.AdressProgramm.ValueExists(_tr.ID);
            }
        };


        // определить делегат поставляющий класс определяющий формат ноды в дереве
        Func<TreeEntitySingle, F_TreeDataSource.F_TreeDataSourceView.F_TreeHierarchyData> formatter = delegate(TreeEntitySingle _tr)
        {

            return (F_TreeDataSource.F_TreeDataSourceView.F_TreeHierarchyData)new TreeNodeFormatter_Rb(_tr, f);
        };

        // сформировать источник данных виз. элемента
        return new F_TreeDataSource(iPageController.TreeDictionaryContext.GetAdressProgramm(), formatter);

    }


    protected virtual F_TreeDataSource GetLocationDescribe(string _DivClass, string _NodeClass, string _HfId)
    {

        // Инициализировать RbCheckBox 
        TreeNodeFormatter_Rb.TreeRbContext f = new TreeNodeFormatter_Rb.TreeRbContext()
        {
            DivClass = _DivClass,
            NodeClass = _NodeClass,
            HfId = _HfId,

            // опредеить функцию решающую нажат чек бокс или нет 
            OnChBind = delegate(TreeEntitySingle _tr)
            {
                if (null == Constraction.LocationDescribe) return false;
                if (_tr.ChildNodes.Count > 0) return false;
                return Constraction.LocationDescribe.ValueExists(_tr.ID);
            }
        };


        // определить делегат поставляющий класс определяющий формат ноды в дереве
        Func<TreeEntitySingle, F_TreeDataSource.F_TreeDataSourceView.F_TreeHierarchyData> formatter = delegate(TreeEntitySingle _tr)
        {

            return (F_TreeDataSource.F_TreeDataSourceView.F_TreeHierarchyData)new TreeNodeFormatter_Rb(_tr, f);
        };

        // сформировать источник данных виз. элемента
        return new F_TreeDataSource(iPageController.TreeDictionaryContext.GetTransportLocation(), formatter);

    }

    protected virtual  F_TreeDataSource GetConstractionType()
    {
        return null;
    }

   



    /// <summary>
    /// Носитель
    /// </summary>
    protected virtual Constraction Constraction
    {
        get
        {
            

           Constraction c= _ws_Constractions.GetConstraction(ConstractionID);           
           c.BusinesRulesEngine.OnError = OnError;
           return c;
        }
         
    }
  
    public bool OnError(List<string> Err)
    {
        string s = ScriptBuilder.GetAlertScript(Err);
        System.Web.UI.ScriptManager.RegisterStartupScript(Page, Page.GetType(), Guid.NewGuid().ToString(), s, true);
        return true;
    }


    protected string DepatmentID { get { return Request.QueryString[qDepartmentID]; } }

    

  
    #region LstView Readers 
   
    protected   class LvReader
    {
        protected Constraction _Constraction= null;
        public virtual  object[] Context { get; set; }
        public virtual List<string> Update(System.Web.UI.Control _ListViewItem) { return new List<string>(); }
        public virtual void ItemDataBound(object sender, ListViewItemEventArgs e) { }
        public virtual IEnumerable DataSource { get; set; }
        public virtual void  Save()
        {
            try
            {
                // сохраняем
                wsConstractions ws = (wsConstractions)GlobalConstants.CurrentAgency.WS_FactoryList[WS_FactoryList.wsKey_Constraction];                                    
                ws.SaveConstraction(_Constraction);   
                
            }
            catch
            {
                throw;
            }
        }
    }
  
    protected class InfoReader : LvReader
    { 
        
        public override object[] Context { get; set; }
        public InfoReader(Constraction Constraction)
        {
            _Constraction = Constraction;
        }
        public override List<string> Update(System.Web.UI.Control _ListViewItem)
        {
            try 
            {
              // обновляем 
            _Constraction.GID =((TextBox)_ListViewItem.FindControl("txtGID")).Text ;            
            _Constraction.dtCreate = Convert.ToDateTime(((TextBox)_ListViewItem.FindControl("TxtdtCreate")).Text);
             string s=((TextBox)_ListViewItem.FindControl("TxtdtDestroyed")).Text;
             if (s.Length > 0) _Constraction.dtDestroy = Convert.ToDateTime(s); 
             _Constraction.bLight =  ((CheckBox )_ListViewItem.FindControl("chLight")).Checked;
             _Constraction.Describe = ((TextBox)_ListViewItem.FindControl("txtDescribe")).Text;            
                
            
            
            
            return new List<string> (); ;
            }
            catch (Exception e)
            {
                List<string> r= new List<string> ();
                r.Add (e.Message);
                return  r;                
            }
        }                
        public override void ItemDataBound(object sender, ListViewItemEventArgs e)
        {
            ;
        }
        public override IEnumerable DataSource
        {
            get;
            set;
        }


    }
    
    protected class AdressReader : LvReader
    {
        Constraction _Constraction;
        public AdressReader(Constraction Constraction)
        {
            _Constraction = Constraction;
        }
        public override List<string> Update(System.Web.UI.Control   _ListViewItem)
        {            
            return new List<string>(); ;
        }
        public override  object[] Context { get; set; }
        public override void ItemDataBound(object sender, ListViewItemEventArgs e)
        {

            TreeView tv = ((TreeView)e.Item.FindControl("tvAdress"));
            if (null == tv) return; //? Это режим редактирования
             
            tv.DataSource = Context[0] ;
            tv.DataBind();

            if (null == _Constraction.Streets) return;
            ListView Streets = ((ListView)e.Item.FindControl("lvStreets"));
            //_Constraction.Streets.ChildNodes.Reset();
            //Streets.DataSource = _Constraction.Streets.ChildNodes;
            Streets.DataBind(); 
        }
        public override IEnumerable DataSource
        {
            get;
            set;
        }
    }

    protected class StreetsReader : LvReader
    {        
        public StreetsReader(Constraction Constraction)
        {
            _Constraction = Constraction;
        }
        public override List<string> Update(System.Web.UI.Control  _ListViewItem)
        {
            try
            {
                string sID =((HiddenField)(_ListViewItem.FindControl("idStreet"))).Value.ToString ();
                String s = ((TextBox)_ListViewItem.FindControl("txtStreet")).Text;
                _Constraction.Streets= s;
                Save();
                return new List<string>(); 
            }
            catch(Exception e)
            {
                List<string> l = new List<string>();
                l.Add(e.Message);
                return l;
            }
        }
        public override object[] Context { get; set; }
        public override void ItemDataBound(object sender, ListViewItemEventArgs e)
        {
            ;
        }
        public override IEnumerable DataSource
        {
            get;
            set;
        }
    }
    #endregion


    
    

    protected virtual void ItemCanceling(object sender, ListViewCancelEventArgs e)
    {

    }
    protected virtual void ItemUpdating(object sender, ListViewUpdateEventArgs e)
    {

    }
    protected virtual void ItemDataBound(object sender, ListViewItemEventArgs e)
    {

    }
   
    protected void ItemInserting(object sender, ListViewInsertEventArgs e)
    {


    }


    //добавление удаление улиц
    protected virtual  void AddStreet(object sender, EventArgs e)
    {
    }
    protected virtual  void RemoveStreet(object sender, EventArgs e)
    {
    }

    public class grdConstraction_EditConstr : grdConstraction
    {
        public grdConstraction_EditConstr(Constraction constr) : base(constr) { }
        public override string ConstractionTypeName
        {
            get
            {
                string s=base.ConstractionTypeName;
                return _Constraction.GID + " | " + s;
            }
        }

    }

    protected grdConstraction_EditConstr brConstraction
    {
        get
        {
            return new grdConstraction_EditConstr(Constraction); 
        }
    }


    protected virtual grdConstraction grdConstraction { get { return new grdConstraction(Constraction); } }

    protected virtual List<grdConstraction> grdConstractionAsCollection
    {
        get
        {
            List<grdConstraction> List = new List<grdConstraction>();
            List.Add (new grdConstraction(Constraction));
            return List;
        }
    }

   // protected void SaveConstraction()
   //{
   //    // сохраняем
   //     ws_Constractions ws = new ws_Constractions();
   //     ws.SaveConstraction(Constraction);

   //}

}
